package com.example.springdemo.controller;

import com.example.springdemo.domain.entity.share.Share;
import com.example.springdemo.domain.entity.user.User;
import com.example.springdemo.service.content.ShareService;
import com.example.springdemo.service.user.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author wanghuajun
 * @version 1.0
 * @date 2019-08-09 21:20
 */
@Slf4j
@RestController
public class TestController {

    @Autowired
    private UserService userService;
    @Autowired
    private ShareService shareService;

    @GetMapping("/user/{id}")
    public User getUser(@PathVariable Integer id) {
        log.info("UserController#getUser被调用------>[id:{}]", id);
        return userService.getUserById(id);
    }

    @GetMapping(value = "/share/{id}")
    public Share getShare(@PathVariable Integer id) {
        log.info("UserController#getShare------>[id:{}]", id);
        return shareService.getShareById(id);
    }

    @PutMapping(value = "/user/{id}")
    public int updateUser(@PathVariable Integer id) {
        User user = User.builder()
                .id(id)
                .avatarUrl("www.jd.com")
                .bonus(50)
                .roles("admin,root")
                .updateTime(new Date())
                .build();
        return userService.updateUser(user);
    }

}
